package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeachplanApi;
import com.xuecheng.api.content.model.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeanchplanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划控制层
 * </p>
 */
@Controller
@Slf4j
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService teachplanService;


    @GetMapping("teachplan/{courseId}/tree-nodes")
    public TeachplanDTO queryTreeNodesByCourseId(@PathVariable Long courseId) {
      //获取机构ID
        Long companyId = SecurityUtil.getCompanyId();
        TeachplanDTO dto = teachplanService.queryTreeNodesByCourseId(courseId, companyId);
        return dto;
    }


    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachplanVO teachplanVO) {
        //获取机构ID
        Long companyId = SecurityUtil.getCompanyId();

        TeachplanDTO dto = TeanchplanConvert.INSTANCE.vo2dto(teachplanVO);

        TeachplanDTO result = teachplanService.createOrModifyTeachPlan(dto,companyId);
        return result;
    }



    @DeleteMapping("teachplan/{teachplanId}")
    public void removeTeachPlan(@PathVariable Long teachPlanId) {
        //1.获得公司Id
        Long companyId = SecurityUtil.getCompanyId();
        //调用service方法
        teachplanService.removeTeachPlan(teachPlanId,companyId);
    }
}
